<template>
    <div>
<h1>门店添加</h1>
<table class="table table-bordered" border="1">
    <tr>
        <td>门店名称</td>
        <td><input type="text" v-model="ad.shop_name"></td>
    </tr>

    <tr>
        <td>分店名称</td>
        <td><input type="text"  v-model="ad.shop_Branchname"></td>
    </tr>

    <tr>
        <td>门店地址</td>
        <td><input type="text"  v-model="ad.shop_Address"></td>
    </tr>

    <tr>
        <td>门店电话</td>
        <td><input type="text"  v-model="ad.shop_pone"></td>
    </tr>

    <tr>
        <td>门店状态</td>
        <td><input type="radio" :value="true"  v-model="ad.shop_zt" >营业中
            <input type="radio" :value="false"   v-model="ad.shop_zt">暂停营业</td>
    </tr>

    <tr>
        <td>门店介绍</td>
        <td><textarea  v-model="ad.shop_js"> </textarea></td>
    </tr>

    <tr>
        <td>入住须知</td>
        <td><textarea  v-model="ad.shop_Nptic"> </textarea></td>
    </tr>

    <tr>
        <td>交通信息</td>
        <td><textarea  v-model="ad.jtxx"> </textarea></td>
    </tr>

    <tr>
        <td>门店预览图</td>
        <td>
            <img style="width: 50px; height: 50px;"  :src="ad.shop_Img" >
            <input type="file" @change="ajdo" ></td>
    </tr>

    <tr>
    <td></td>
    <td><input type="button" value="添加" @click="pdad"></td>
</tr>

</table>
    </div>
</template>

<script setup lang="ts">
import { ref } from "vue";
import axios from "axios";

const file=ref(null);

const ajdo=(e:any)=>{
    file.value= e.target.files[0]

if(!file.value)
{
alert('请选择一个文件上传');
return;

}

const fordate=new FormData();

fordate.append("imge",file.value);
axios.post('https://localhost:7268/api/wjsc/fileupload',fordate)
.then(res=>{

    if(res.data.fileconm_cod==0)
{

alert(res.data.fileconm_msg);

}
else if(res.data.fileconm_cod==1)
{

    alert(res.data.fileconm_msg);

}
else{
    alert(res.data.fileconm_msg);
    console.log(res.data)
    ad.value.shop_Img=res.data.fileconm_Path

}
  


})
.catch(error=>{


    console.log(error); 
})
}




const ad=ref({


    shop_id: 0,
  shop_name: "",
  shop_Branchname: "",
  shop_Address: "",
  shop_pone: "",
  shop_zt: true,
  shop_js: "",
  shop_Nptic: "",
  jtxx: "",
  shop_Img: ""


})



const pdad =()=>{

if(ad.value.shop_name=="")
{
alert('不能为空');
return;
}
axios.post('https://localhost:7268/api/md/mdadd',ad.value)


.then(res=>{

if(res.data==-1){

alert('该店面已被注册');

}
if(res.data>0){

  alert('注册成功');


}
else{

    alert('注册失败');
}

})
.catch(error=>{

console.log(error);

})

}


</script>

<style scoped>

</style>